
// 获取网址后面参数

    var test = window.location.href;
    var url = test;
    var arr = url.split("?");
    var Newarr = arr[1];
    var arr1 = Newarr.split("&");
    var obj = {};
    var price;
    var watch;
    var nofree;
    var learnNum;
    for (var i = 0; i < arr1.length; i++) {
        obj[arr1[i].split('=')[0]] = arr1[i].split('=')[1];
    }



// 评论接口
// urlObj();
request(`http://wkt.myhope365.com//pc/comment/commentList/course/${obj.id}`, type = "get",
    {
        pageNum: 1,
        pageSize: 10,
    }
).then((res) => {
    $('.comments').append('<ul></ul>')
    $.each(res.rows, function (index, value) {
        $('.comments>ul').append('<li></li>');
        $('.comments>ul>li:last-child').append(`
        <div class="avatar"><img src="images/个人.png" alt="">
        </div>
        <section class="right">
            <p class="name">${value.user.nickname}</p>
            <span class="com">${value.commentContent}</span>
            <span class="time">${value.updatedTime}<span>
        </section>
        `);
    })
})
// 课程描述tab切换
$('.title>li').click(function () {
    $('.title>li').css('border-color', 'transparent').eq($(this).index()).css('border-color', '#23db9b');
    $('.contain>li').css('display', 'none').eq($(this).index()).css('display', 'block');
})
// 获取课程,描述,目录接口
request(`http://wkt.myhope365.com//pc/course/detail/${obj.id}`, type = "get",
).then((res) => {
    learnNum = res.data.participationsCount;
    if (res.data.isFree == 1) {
        price = '免费'
        watch = '立即观看'
        $('main>main>section>.price').text(`${price}`)
        $('.watch').append(`<button class="sectionBtn">${watch}</button>`)
    } else {
        price = res.data.coursePrice
        watch = '立即购买'
        nofree = '加入购物车'
        $('main>main>section>.price').text(`￥${price}`)
        $('.watch').append(`<button class="firstBtn">${watch}</button>`)
        $('.watch').append(`<button class="sectionBtn">${nofree}</button>`)
    }
    $('main>main>img').attr('src', `${res.data.coverFileUrl}`)
    $('.people').text(`累计${learnNum}人学习`)
    $('main>main>section>.title').text(`${res.data.courseTitle}`)
    $('.description').append(`${res.data.courseDetail}`)
    $('.classList').append(`<ul></ul>`)
    $.each(res.data.sections, function (index, value) {
        // 内容添加li  
        $('.classList>ul').append(`<li></li>`)
        // 每个li添加
        $('.classList>ul>li:last-child').append(`<ul><p>${index + 1}.&nbsp;&nbsp;${value.sectionName}</p></ul>`);
        $.each(value.subSections, function (indexs, values) {
            $('.classList>ul>li:last-child>ul').append(
                `<li>${index + 1}-${indexs + 1}&nbsp;&nbsp;${value.subSections[indexs].sectionName}</li>`
            )

        })
    })
})

// 评论框变色
borderColor($('.searchText>input'), '#00cf8c', '#ccc')
borderColor($('.addCom>textarea'), '#00cf8c', '#ccc')
function borderColor(who,beforeColor,afterColor) {
    who.on(
        {
            focus() {
                who.css( 'border-color', beforeColor )
            },
            blur() {
                who.css('border-color', afterColor)
            }
    })
}



